package com.spark.lola.controller.purchaser;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.spark.lola.entity.pur.ReturnOrderInfo;
import com.spark.lola.mapper.pur.ReturnOrderInfoMapper;
import com.spark.lola.service.pur.IReturnOrderInfoService;
import com.spark.lola.support.api.entity.EnterpriseTokenUser;
import com.spark.lola.support.common.util.ResponseBean;
import com.spark.lola.support.mybatis.entity.PageParam;
import com.spark.lola.support.mybatis.entity.QueryParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Zhi-peng wang
 * @date: 2020/05/25 16:54
 **/
@RestController
@RequestMapping(value = "/api/pur/return-order", produces = "application/json;charset=utf-8")
@Api(value = "/api/pur/return-order", tags = "退货单接口")
public class ReturnOrderController {

    @Autowired
    private ReturnOrderInfoMapper currentMapper;

    @Autowired
    private IReturnOrderInfoService currentService;

    @ApiOperation(value = "分页查询退货单")
    @RequestMapping(value = "/findBy", method = RequestMethod.POST)
    public ResponseBean findBy(@RequestBody QueryParam<ReturnOrderInfo> queryBean,
                               @SessionAttribute EnterpriseTokenUser<?> tokenUser) {
        PageParam<ReturnOrderInfo> pageParam = queryBean.toPageParam();
        IPage<ReturnOrderInfo> page = currentMapper.page(pageParam.getPage(), pageParam.getEntityWrapper());
        return ResponseBean.success(page);
    }

    @ApiOperation(value = "查询退货单详情")
    @RequestMapping(value = "/findInfo/{returnOrderId}", method = RequestMethod.POST)
    public ResponseBean findInfo(@PathVariable Long returnOrderId,
                                 @SessionAttribute EnterpriseTokenUser<?> tokenUser) {
        ReturnOrderInfo model = currentService.findFullById(returnOrderId);
        return ResponseBean.success(model);
    }

}
